package com.ysm.freestyle.test.jetpack

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.ysm.freestyle.R
import com.ysm.freestyle.base.BaseActivity
import com.ysm.freestyle.databinding.ActivityLiveDataBinding

class LiveDataActivity : BaseActivity() {
    private val mContent = MutableLiveData<String>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_live_data)
        val binding = DataBindingUtil.setContentView<ActivityLiveDataBinding>(this,
            R.layout.activity_live_data
        )

        val observer = object : Observer<String> {
            override fun onChanged(it: String) {
                Log.i(TAG,"===> $it")
            }
        }

        mContent.observe(this){
            Log.i(TAG,"===> $it")
        }
        mContent.observe(this,observer)
        mContent.observe(this,object : Observer<String> {
            override fun onChanged(it: String) {
                Log.i(TAG,"===> $it")
            }
        })
    }

    fun update(view: View){
        mContent.value = "new String!!!"

    }

}